<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%@ page import="com.scalar.chiptrack.commons.Constants,
                 com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.sales.LineItem,
                 com.scalar.chiptrack.users.Functionality,
                 com.scalar.chiptrack.users.User,
                 java.util.ArrayList,
                 org.apache.struts.util.LabelValueBean,
                 java.util.HashMap,
                 com.scalar.chiptrack.commons.SessionKeys"%>
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<% User user1 = (User) session.getAttribute (SessionKeys.USER_KEY); %>
<% ArrayList orderList = ( ArrayList ) request.getAttribute( "presentLineItems" );
    int listSize = orderList.size();
   //begin: added by Sujan on 14th dec 2004 to get the holds of a line item which r displayed in current line items.
    HashMap presentLineItemsMap = new HashMap();
    LineItem presentLineItem = null;
      for ( int k=0; k < listSize; k++ )
      {
          presentLineItem = ( LineItem )orderList.get( k );
          presentLineItemsMap.put( new Integer( presentLineItem.getLineItemId()), presentLineItem );
      }
   //end: sujan
		   %>


<% int index = 0;
    int noOfColumnsBeforeQty = 4;
%>
<logic:iterate id="myHashMap" name="lineItemsWithSubtotals">
    <logic:iterate id="lineItemList" name="myHashMap" >
          <logic:iterate id="LineItem" name="lineItemList" property="key" type="com.scalar.chiptrack.sales.LineItem">

         <input type="hidden" name="Line_Item_No" value="<%=LineItem.getLineItemNo()%>">
         <input type="hidden" name="cancelStatus" value="<%=LineItem.getIsCancel()%>">

         <tr>
	       <td width="5%" bgcolor="#DEE1E2">
                <font class="bodytext"><bean:write name="LineItem" property="lineItemNo" /></font></td>
                <input type="hidden" name="lineItemId" value="<%=LineItem.getLineItemId()%>"/>


	       <td width="8%" bgcolor="#DEE1E2" nowrap>
                <font class="bodytext"><bean:write name="LineItem" property="manufacturingPartNo" /></font></td>
           <% if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_MARKETING_PART_NUMBER)) { %>
                <td width="8%" bgcolor="#DEE1E2" nowrap><font class="bodytext"><bean:write name="LineItem" property="marketingPartNo"/></font></td>
           <% noOfColumnsBeforeQty = (index==0) ? noOfColumnsBeforeQty+1 : noOfColumnsBeforeQty; } %>
           <td width="8%" bgcolor="#DEE1E2" nowrap>
                <font class="bodytext"><bean:write name="LineItem" property="customerPartNo" /></font></td>
           <td width="1%" bgcolor="#DEE1E2" class="bodytext" align=center>
                <bean:write name="LineItem" property="isTaxableAsString"/></td>
	       <td width="5%" bgcolor="#DEE1E2" align=right>
                <font class="bodytext"><bean:write name="LineItem" property="qtyAsString" /></font></td>
           <td width="8%" bgcolor="#DEE1E2" align=right>
                <font class="bodytext"><bean:write name="LineItem" property="unitPriceAsString" /></font></td>
           <td width="8%" bgcolor="#DEE1E2" align=right>
                <font class="bodytext"><bean:write name="LineItem" property="amountAsString" /></font></td>
           <td width="8%" bgcolor="#DEE1E2">
                <font class="bodytext"><bean:write name="LineItem" property="requestDate" /></font></td>
                <input type="hidden" name="requestDate" value="<%=LineItem.getRequestDate()%>">
           <td width="8%" bgcolor="#DEE1E2">
                <font class="bodytext">
                <%  // LineItem orders = (LineItem)orderList.get ( i );
                    LineItem orders = ( LineItem ) presentLineItemsMap.get ( new Integer ( LineItem.getLineItemId()) );

					boolean noHolds = false;
					if ( ( orders.getMarketingHold().length () == 0 ) &&
						( orders.getSalesHold().length () == 0 ) &&
						( orders.getOperationsHold().length () == 0 ) &&
						( orders.getFinanceHold().length () == 0 ) ) {
						noHolds = true;

						}
                %>
                <logic:empty name="LineItem" property="suggScheduleDate">
                <%
                    if((user1.isActionAllowed (Functionality.ORDER_SCHEDULING, User.USER_ACTION_VIEW)) == true && (user1.isActionAllowed (Functionality.ORDER_SCHEDULING, User.USER_ACTION_MODIFY)) == true )
                    {
                %>
                    <A href="javascript:scheduleLineItem ('<bean:write name="LineItem" property="manufacturingPartNo"/>', '<bean:write name="LineItem" property="lineItemNo" />', '<bean:write name="LineItem" property="salesOrderId"/>', '<bean:write name="LineItem" property="requestDate"/>', '<bean:write name="LineItem" property="quantity"/>');" onmouseover="window.status='Click to Schedule';return true" onmouseout="window.status='';return true" >Schedule</A>
                <%
                    }
                    else
                    {
                %>
                    Schedule
                <%
                    }
                %>
                </logic:empty>
                <logic:notEmpty name="LineItem" property="suggScheduleDate">
                <logic:notMatch name="LineItem" property="suggScheduleDate" value="/">
                <% if((user1.isActionAllowed (Functionality.ORDER_SCHEDULING, User.USER_ACTION_VIEW)) == true && (user1.isActionAllowed (Functionality.ORDER_SCHEDULING, User.USER_ACTION_MODIFY)) == true ){ %>

                        <A href="javascript:scheduleLineItem ('<bean:write name="LineItem" property="manufacturingPartNo"/>', '<bean:write name="LineItem" property="lineItemNo" />', '<bean:write name="LineItem" property="salesOrderId"/>', '<bean:write name="LineItem" property="requestDate"/>', '<bean:write name="LineItem" property="quantity"/>');">Schedule</A>
                <% } else { %>
                    Schedule
                <% } %>
                </logic:notMatch>

                <logic:match name="LineItem" property="suggScheduleDate" value="/">
                <% if((user1.isActionAllowed (Functionality.ORDER_SCHEDULING, User.USER_ACTION_VIEW)) == true && (user1.isActionAllowed (Functionality.ORDER_SCHEDULING, User.USER_ACTION_MODIFY)) == true ){ %>
                    <A href="javascript:openScheduling('<bean:write name="LineItem" property="manufacturingPartNo"/>', '<bean:write name="LineItem" property="lineItemNo" />', '<bean:write name="LineItem" property="salesOrderId"/>');" ><bean:write name="LineItem" property="suggScheduleDate"/></A>

                <% } else { %>
                    <bean:write name="LineItem" property="suggScheduleDate"/>
                <% } %>
                </logic:match>
                </logic:notEmpty>
                </font></td>
				<td width="8%" bgcolor="#DEE1E2" nowrap>
				<% if((user1.isActionAllowed (Functionality.ORDER_SCHEDULING, User.USER_ACTION_VIEW)) == true && (user1.isActionAllowed (Functionality.ORDER_SCHEDULING, User.USER_ACTION_MODIFY)) == true )  { %>
				<font class="bodytext"><html:text name="LineItem" property="scheduleDate" size='11' styleClass='txfield' onkeypress="return noenter()"  onblur="javascript:giveMsg()" /></font>
                 <a href="javascript: if(document.approverOrderForm.scheduleDate.length!=null)
                                 {
                                    openScheduleCalendar( document.approverOrderForm.scheduleDate[<%= index %>],'<%=LineItem.getRequestDate()%>')
                                 }
                                 else
                                 {
                                    openScheduleCalendar(document.approverOrderForm.scheduleDate,'<%=LineItem.getRequestDate()%>')
                                  }" >
                <img onMouseOver="window.status='Click here to select date';return true" border="0" align='center' src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20>
                </a>
                <% } else { %>
				<font class="bodytext"><html:text name="LineItem" property="scheduleDate" size='11' styleClass='txfield' disabled="true" onkeypress="return noenter()" /></font>
				<% } %>
           <td width="8%" bgcolor="#DEE1E2">
                <font class="bodytext"><bean:write name="LineItem" property="revisedDate" /></font></td>
           </td>
           <td width="20%" bgcolor="#DEE1E2">
                <table with="100%">
                <tr>
                    <td class="NArialL">
                        <% if(user1.isActionAllowed (Functionality.MARKETING_HOLDS_RELEASE, User.USER_ACTION_MODIFY)) { %>

                        <% if ( noHolds ) { %>
							<html:select name="LineItem" property="marketingHold" styleClass="txfield" disabled="true">
								<html:option value=""></html:option>
								<html:option value="0">X</html:option>
								<html:options collection="marketingReasonCodes" property="value" labelProperty="label"/>&nbsp;
							</html:select>
							<% } else { %>
							<html:select name="LineItem" property="marketingHold" styleClass="txfield">
								<html:option value=""></html:option>
								<html:option value="0">X</html:option>
								<html:options collection="marketingReasonCodes" property="value" labelProperty="label"/>&nbsp;
							</html:select>
							<% } %>

                        <% } else { %>
                        <html:select name="LineItem" property="marketingHold" styleClass="txfield" disabled="true">
                            <html:option value=""></html:option>
                            <html:option value="0">X</html:option>
                            <html:options collection="marketingReasonCodes" property="value" labelProperty="label"/>&nbsp;
                        </html:select>
                        <% } %>
                    </td>
                    <td class="NArialL">
                        <% if(user1.isActionAllowed (Functionality.FINANCE_HOLDS_RELEASE, User.USER_ACTION_MODIFY)) { %>
                           <% if ( noHolds ) { %>
							<html:select name="LineItem" property="financeHold" styleClass="txfield" disabled="true">
								<html:option value=""></html:option>
								<html:option value="0">X</html:option>
								<html:options collection="financeReasonCodes" property="value" labelProperty="label"/>&nbsp;
							</html:select>
							<% } else {%>
							<html:select name="LineItem" property="financeHold" styleClass="txfield">
								<html:option value=""></html:option>
								<html:option value="0">X</html:option>
								<html:options collection="financeReasonCodes" property="value" labelProperty="label"/>&nbsp;
							</html:select>
							<% } %>
                        <% } else { %>
                            <html:select name="LineItem" property="financeHold" styleClass="txfield" disabled="true">
                                <html:option value=""></html:option>
                                <html:option value="0">X</html:option>
                                <html:options collection="financeReasonCodes" property="value" labelProperty="label"/>&nbsp;
                            </html:select>
                        <% } %>
                    </td>
                    <td class="NArialL">
                        <% if(user1.isActionAllowed (Functionality.OPERATIONS_HOLDS_RELEASE, User.USER_ACTION_MODIFY)) { %>
                            <% if ( noHolds ) { %>

							<html:select name="LineItem" property="operationsHold" styleClass="txfield" disabled="true">
								<html:option value=""></html:option>
								<html:option value="0">X</html:option>
								<html:options collection="opsReasonCodes" property="value" labelProperty="label"/>&nbsp;
							</html:select>
							<% } else {%>

                            <html:select name="LineItem" property="operationsHold" styleClass="txfield" onchange="javascript:giveMsg()">
								<html:option value=""></html:option>
								<html:option value="0">X</html:option>
                                <html:options collection="opsReasonCodes" property="value" labelProperty="label"/>&nbsp;
							</html:select>

							<% } %>
                        <% } else { %>
                        <html:select name="LineItem" property="operationsHold" styleClass="txfield" disabled="true">
                            <html:option value=""></html:option>
                            <html:option value="0">X</html:option>
                            <html:options collection="opsReasonCodes" property="value" labelProperty="label"/>&nbsp;
                        </html:select>
                        <% } %>
                    </td>
                    <td class="NArialL">



                        <%   ArrayList reasonCodes = (ArrayList)request.getAttribute("salesReasonCodes");
                             LabelValueBean lvBean = null;
                        %>

                         <% if(user1.isActionAllowed (Functionality.SALES_HOLDS_RELEASE, User.USER_ACTION_MODIFY)) { %>
                         <% if ( noHolds ) { %>
							<html:select name="LineItem" property="salesHold" styleClass="txfield" disabled="true">
								<html:option value=""></html:option>
								<html:option value="0">X</html:option>
                               <% for(int rCode=0;rCode<reasonCodes.size();rCode++){
                                   lvBean = (LabelValueBean) reasonCodes.get(rCode);
                               %>
                                   <option value="<%=lvBean.getValue()%>"><%=lvBean.getLabel()%></option>
                               <%}%>
                            </html:select>
					  	<% } else {%>
							<html:select name="LineItem" property="salesHold" styleClass="txfield">
								<html:option value=""></html:option>
								<html:option value="0">X</html:option>
								<html:options collection="salesReasonCodes" property="value" labelProperty="label"/>&nbsp;
							</html:select>
							<% } %>
                        <% } else { %>
                        <html:select name="LineItem" property="salesHold" styleClass="txfield" disabled="true">
                            <html:option value=""></html:option>
                            <html:option value="0">X</html:option>
                            <html:options collection="salesReasonCodes" property="value" labelProperty="label"/>&nbsp;
                        </html:select>
                        <% } %>
                    </td>
                </tr>
            </table>
           </td>
        </tr>
        <% index++;%>
       </logic:iterate>
        <tr>
            <td colspan="<%=noOfColumnsBeforeQty%>" width="15%" bgcolor="#FFFFFF" class="NArialL" align="right">
                Sub Total
            </td>
            <bean:define id="subTotal" name="lineItemList" property="value" type="com.scalar.chiptrack.sales.SubTotal"/>
            <td colspan="1" width="15%" bgcolor="#FFFFFF" class="NArialL" align="right">
                <bean:write name="subTotal" property="subTotalQty" />
            </td>
            <td>&nbsp;</td>
            <td colspan="1" width="15%" bgcolor="#FFFFFF" class="NArialL" align="right">
                <bean:write name="subTotal" property="subTotalAmt" />
            </td>
        </tr>
     </logic:iterate>
</logic:iterate>
